﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using MyFloridaHouse.DataAccess.Extensions;
using MyFloridaHouse.libSvDTO;
using MyFloridaHouse.DataAccess.DTO;

namespace MyFloridaHouse.DataAccess
{
    public partial class DAL_CensusData
    {

        /// <summary>
        /// Gets the regions in view.
        /// </summary>
        /// <param name="iZoomLevel">The izoomlevel.</param>
        /// <param name="iLayerID">The ilayerID.</param>
        /// <param name="iNorth">The inorth.</param>
        /// <param name="iEast">The ieast.</param>
        /// <param name="iSouth">The isouth.</param>
        /// <param name="iWest">The iwest.</param>
        /// <returns>List of <see cref="RegionDTO"/></returns>
        /// <remarks>SPROC: usp_moGetRegionsInView</remarks>
        public List<SQLRegionDTO> xgetRegionsInView(double iZoomlevel, int iLayerID, double iNorth, double iEast, double iSouth, double iWest)
        {
            List<SQLRegionDTO> itemList = new List<SQLRegionDTO>();
            string storedProcedureName = "usp_tl10GetRegionsDataInView10";

            using (SqlConnection db = Connect())
            {
                SqlCommand StoredProcedureCommand = new SqlCommand(storedProcedureName, db);
                StoredProcedureCommand.CommandType = CommandType.StoredProcedure;
                SqlParameter dataPartIDParm = StoredProcedureCommand.Parameters.AddWithValue("iZoomlevel", iZoomlevel);
                dataPartIDParm.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm2 = StoredProcedureCommand.Parameters.AddWithValue("iLayerID", iLayerID);
                dataPartIDParm2.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm3 = StoredProcedureCommand.Parameters.AddWithValue("iNorth", iNorth);
                dataPartIDParm3.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm4 = StoredProcedureCommand.Parameters.AddWithValue("iEast", iEast);
                dataPartIDParm4.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm5 = StoredProcedureCommand.Parameters.AddWithValue("iSouth", iSouth);
                dataPartIDParm5.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm6 = StoredProcedureCommand.Parameters.AddWithValue("iWest", iWest);
                dataPartIDParm6.Direction = ParameterDirection.Input;

                db.Open();
                using (SqlDataReader rdr = StoredProcedureCommand.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        itemList.Add(SQLRegionDTODataContract.DataContract(rdr));
                    }
                }
            }

            //Database db = Connect();

            //DbCommand dbCommand = db.GetStoredProcCommand("usp_moGetRegionsInView");
            //db.AddInParameter(dbCommand, "iZoomlevel", DbType.Double, iZoomLevel);
            //db.AddInParameter(dbCommand, "iLayerID", DbType.Int32, iLayerID);
            //db.AddInParameter(dbCommand, "iNorth", DbType.Double, iNorth);
            //db.AddInParameter(dbCommand, "iEast", DbType.Double, iEast);
            //db.AddInParameter(dbCommand, "iSouth", DbType.Double, iSouth);
            //db.AddInParameter(dbCommand, "iWest", DbType.Double, iWest);
            //using (IDataReader rdr = db.ExecuteReader(dbCommand))
            //{
            //    while (rdr.Read())
            //    {
            //        itemList.Add(RegionDTODataContract.DataContract(rdr));
            //    }
            //}

            return itemList;
        }

    }
}
